architecture = x86

ifeq (${architecture}, x86)
ALL : x86
TARGET_D_LIB :=-lz  -luuid -levent  -lpthread -lzdb   -lcrypto   -lmosquitto    -lm -ldl  -lconfig -lssl
CFLAGS = -g -O2 -Winline   
### -D __MSGPACKC__
else
ALL : 9531
TARGET_D_LIB :=-lz -luuid -levent  -lpthread  -lzdb   -lcrypto -luuid -lmosquitto    -lm -ldl -lsodium 
CFLAGS = -g -O2 -Winline  
endif
TARGET_NAME = coad

SRC_BASE = .
INSTALL_PATH = 
CC = gcc
LIB_NAME = lib${TARGET_NAME}.a
LIBSO_NAME	= lib${TARGET_NAME}.so
OBJ_DIR = obj



FILES = $(wildcard $(SRC_BASE)/*.c)
TMP_C = $(notdir $(FILES))
OBJS = $(TMP_C:%.c=$(OBJ_DIR)/%.o)
SUBDIRS = $(patsubst %/,%,$(dir $(wildcard */Makefile)))

.PHONY: make_target
make_target: $(OBJ_DIR) $(OBJS) $(SUBDIRS)
	$(CC) $(CFLAGS) $(OBJS)  ${TARGET_D_LIB} -o $(TARGET_NAME)
	$(CC) -fPIC -shared  $(OBJS) ${TARGET_D_LIB} -o $(LIBSO_NAME)
	

.PHONY: x86
x86: make_target

.PHONY: 9531
9531: make_target

.PHONY: all
all: make_target

.PHONY: install
install:
	cp $(TARGET_NAME) $(INSTALL_PATH)	

$(OBJ_DIR):
	-mkdir $(OBJ_DIR)
	echo $(TMP_C)

$(OBJ_DIR)/%.o:	$(SRC_BASE)/%.c
	$(CC) -c -fPIC $(CFLAGS) $(CFLAGS_$(<:.c=.o)) $(IFLAGS) $(IFLAGS_$(<:.c=.o)) -o $@ $<

.PHONY: clean
clean:
	rm -rf $(OBJ_DIR)
	rm -rf $(TARGET_NAME)
	rm -rf $(LIBSO_NAME)
